﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace Jemgine.Engine.Scripts
{
    [Category("Physics"), Node]
   public class CircularGravity: Data.ScriptNode
    {
        public float GravityForce { get; set; }

       public CircularGravity()
       {
           AddInput("Fire", typeof(Physics));
           AddOutput("Relay", null);
           GravityForce = 80;
       }

       private Vector2 CalcGravity(Vector2 Pos)
       {
           Vector2 Result = Position - Pos;
           Result.Normalize();
           return Result * GravityForce;
       }

       public override void FireTerminal(int InputID, Data.ScriptPayload Payload)
       {
           if (Payload.Physics != null)
               Payload.Physics.SetGravity(CalcGravity(Payload.Physics.PhysicsBody.GetPosition()));
           OutputTerminals[0].Fire(Payload);           
       }

      
    }
}
